<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class Logevent
{
    protected $obj;
    protected $sesja;
    
    public function __construct()
    {
        $this->obj =& get_instance();
    }
    
    public function log_event($sesja,$state)
    {
        $tab['event_sql']   = $this->obj->db->last_query();
        if(isset($sesja['id']))
        {
            $tab['user_id'] = $sesja['id'];
            $tab['user_typ']= $sesja['typ'];
        }
        else
            $tab['user_id'] = $tab['user_typ'] = 0;
        $tab['event_state'] = $state;
        $tab['user_agent']  = $_SERVER['HTTP_USER_AGENT'];
        if(!empty($_SERVER['HTTP_CLIENT_IP']))
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        else
            $ip = $_SERVER['REMOTE_ADDR'];
        $tab['user_ip'] = ip2long($ip);
        $this->obj->db->insert('ut_event_log',$tab);
    }
}
?>
